<?php
/**
 * Created by PhpStorm.
 * User: zhangrongxiang
 * Date: 2018/2/5
 * Time: 下午11:00
 */

$str = "Life is short,I use PHP";
$por = mb_strripos( $str, "php", 10 );
echo $por . PHP_EOL; //20

function startsWith( $haystack, $needle ) {
	$res = false;
	if ( mb_strripos( $haystack, $needle, 0, "utf-8" ) === 0 ) {
		$res = true;
	}
	
	return $res;
}

function endsWith( $haystack, $needle ) {
	$res = false;
	$len = mb_strlen( $haystack );
	$pos = $len - mb_strlen( $needle );
	if ( mb_strripos( $haystack, $needle, 0, "utf-8" ) === $pos ) {
		$res = true;
	}
	
	return $res;
}

if ( startsWith( $str, "life" ) ) {
	//true
	echo "startsWith($str,life)" . PHP_EOL;
}

if ( startsWith( $str, "php" ) ) {
	echo "startsWith($str,php)" . PHP_EOL;
} else {
	//false
	echo "No startsWith($str,php)" . PHP_EOL;
}

if ( endsWith( $str, "php" ) ) {
	//true
	echo "endsWith($str,php)" . PHP_EOL;
}

if ( endsWith( $str, "life" ) ) {
	echo "endsWith($str,life)" . PHP_EOL;
} else {
	//false
	echo "No endsWith($str,life)" . PHP_EOL;
}

